BackUser_Information=[
    {"name":"张三","Bank_card_number":"0000000000000000","assword":"111111","Balance":"10000"},
    {"name":"李四","Bank_card_number":"1111111111111111","Password":"222222","Balance":"99999"},
    {"name":"王二","Bank_card_number":"2222222222222222","Password":"333333","Balance":"1000"},
    {"name":"赵五","Bank_card_number":"3333333333333333","Password":"444444","Balance":"2000"},
    {"name":"刘大","Bank_card_number":"4444444444444444","Password":"555555","Balance":"0"},
    {"name":"六六六","Bank_card_number":"5555555555555555","Password":"666666","Balance":"6666"}]
#声明全局变量
Input_Username=0
Input_Password=0

'''登录函数，校验账户密码'''
def Login():
    global Input_Username
    Input_Username = input("请输入银行卡卡号：")
    if len(Input_Username)!=16:
        print("账户输入不合法，请确认后重新输入....")
        return
    print('')
    global Input_Password
    Input_Password = input("请输入六位用户密码：")
    if Passwork_Check(Input_Password)==False:
        print("密码输入不合法，请重新输入....")
        return
    if len(Input_Username)==16 and Passwork_Check(Input_Password)==True:
        print("校验通过")

'''定义密码格式校验函数'''
def Passwork_Check(P):
    if P.isdecimal()==False or len(P)!=6:
        return False
    return True
'''验证卡号与密码函数'''
def User_Pass_Check(Username,PassWord):
    for i in range(len(BackUser_Information)):#获取用户在系统中存储的ID
        if Username==BackUser_Information[i]["Bank_card_number"] and PassWord==BackUser_Information[i]["Password"]:
            return i

'''校验输入的字符是否为数字'''
def Numbercheck(num):
    if num.isdecimal():#检验输入是否为数字
        return True
    return False

'''欢迎界面'''
def ATM_Welcome():
    print("="*72)
    print(" "*24,"欢迎使用逗比银行ATM机")
    print("="*72)
    print("*"*72)
    print("*"*30,"登录（1）","*"*31)
    print("*"*30,"退出（2）","*"*31)
    print("*"*72)
    Select_Features = input('请选择需要使用的功能，输入对应数字即可：')
    if Numbercheck(Select_Features) and int(Select_Features)>0 and 4>int(Select_Features):
        Select_Features=int(Select_Features)
        if Select_Features==1:
            Login()
        elif Select_Features==2:
            exit(0)

'''用户登录成功后操作界面的函数'''
def interface():
    print("="*11,"用户操作界面","="*12)
    print("{0:2} {1:12} {2:12} {3:12}".format("  ","1. 查询","2. 取款","3. 存款"),"\n")
    print("{0:2} {1:10} {2:12}".format("  ","4. 修改密码","5. 退出"),"\n")
    print("="*42)

'''用户账户信息查询函数'''
def use_Inquire(USEID):
    print("+"*15,"信息查询","+"*15)
    print("|{0:<4}|{1:<20}|{2:<10}|\r\n".format("账户名","卡号","余额(¥)"))
    print("|{0:<4}|{1:<20}|{2:<10}|\r\n".format(BackUser_Information[USEID]["name"],BackUser_Information[USEID]["Bank_card_number"],BackUser_Information[USEID]["Balance"]))

'''用户取款函数'''
def use_Withdrawal(USEID,Money_Out):
    MoneyNum=int(BackUser_Information[USEID]["Balance"])-int(Money_Out)
    if MoneyNum>=0:
        BackUser_Information[USEID]["Balance"]=MoneyNum
    else:
        print("账户余额不足！")

'''用户存款函数'''
def use_deposit(USEID,Money_Inpout):
    MoneyNum=int(BackUser_Information[USEID]["Balance"])+int(Money_Inpout)
    BackUser_Information[USEID]["Balance"]=MoneyNum

'''用户密码修改函数'''
def Passwor_modify(USEID,OldPassword,New_password1,New_Password2):
    if OldPassword == BackUser_Information[USEID]["Password"]:
        if New_password1==New_Password2:
            BackUser_Information[USEID]["Password"]=New_Password2
            print("密码已修改成功")
            return
        else:
            print("两次输入密码不相同，密码修改失败！")
            return
    else:
        print("旧密码输入错误！")
        return
login_Check=3#用户密码输入错误次数
while True:
    ATM_Welcome()
    use_id= User_Pass_Check(Input_Username,Input_Password)
    if use_id !=None:
        print("登陆成功")
        while True:
            interface()
            OpenWork = input("请选择需要进行的操作：")
            print()
            if OpenWork == "1":
                print("+"*20,"","+"*20)
                use_Inquire(use_id)
                input("按任意键返回上层..")
                print()
            elif OpenWork == "2":
                print("+"*20,"取款界面","+"*20)
                Money_num = input("请输入取款金额：")
                print()
                use_Withdrawal(use_id,Money_num)
                use_Inquire(use_id)
                input("按任意键返回上层..")
                print()
            elif OpenWork =="3":
                print("+"*20,"存款界面","+"*20)
                Money_num = input("请输入存款金额：")
                print()
                use_deposit(use_id,Money_num)
                use_Inquire(use_id)
                input("按任意键返回上层..")
                print()
            elif OpenWork =="4":
                print("+"*20,"密码管理","+"*20)
                OldPassword = input("请输入旧密码：")
                if Passwork_Check(OldPassword) and OldPassword==BackUser_Information[use_id]["Password"]:
                    newpassword1 = input("请输入新密码：")
                    newpassword2 = input("请再次次输入新密码：")
                    if newpassword1==newpassword2:
                        Passwor_modify(use_id,OldPassword,newpassword1,newpassword2)
                    else:
                        print("两次密码不同请重新输入..")
                else:
                    print("旧密码输入错误...")
                    break
            elif OpenWork == "5":
                print("*"*30,"欢迎下次使用！","*"*30)
                break
            else:
                print("无此选项")
    else:
        if len(Input_Username)==16:
            print(Input_Username)
            if(login_Check>1):
                print("密码错误请重新输入，您还有",login_Check-1,"次机会")
                login_Check -= 1
            else:
                print("对不起，密码输入错误次数已达3次")
                break
        else:
            print("回到初始界面，请重新选择。")
            
            
    

    
